package com.leo;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * @ClassName SpinnerDemo
 * @Description
 * @Author wangss
 * @date 2020.05.26 15:01
 * @Version 1.0
 */
public class SpinnerDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

//        Spinner<Integer> spinner = new Spinner<>(0, 10, 5);

        ObservableList<String> list = FXCollections.observableArrayList();
        list.addAll("item1", "item2", "item3");

        Spinner<String> spinner = new Spinner<>(list);
        spinner.setEditable(true);
        // 添加样式
        spinner.getStyleClass().add(Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL);

        AnchorPane.setTopAnchor(spinner, 20d);
        AnchorPane.setLeftAnchor(spinner, 20d);
        anchorPane.getChildren().add(spinner);

        primaryStage.setScene(scene);
        primaryStage.setTitle("spinner");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        spinner.valueProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {

            }
        });

    }
}
